package ten.test_10_15;

import java.util.Map;
import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n  = sc.nextInt();
            int k = sc.nextInt();
            System.out.println(getMax(n,k));
        }
    }
    public static int getMax(int n,int k) {
        int[][] dp = new int[n+1][k + 1];
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= k; j++) {
                dp[i][j] = Integer.MIN_VALUE;
            }
        }
        for(int i = 1; i <= n; i++) {
            dp[i][0] = 0;
        }
        for (int i = 1; i <= n; i++) {
            for(int j = 1; j <= k; j++) {
                dp[i][j] = Math.max(dp[i][j],dp[i-1][j]);
                if(i >= 2) {
                    dp[i][j] = Math.max(dp[i][j],dp[i - 2][j - 1] + 1);
                } else {
                    dp[i][j] = Math.max(dp[i][j],1);
                }
            }

        }
        return dp[n][k];
    }
}
